#include "games/progressgame.h"

ProgressGame::ProgressGame(QWidget *parent, int difflvl) :
    BaseGame(parent, difflvl)
{
    progbar = new QProgressBar(this);
    lay->addWidget(progbar);

    timer = new QTimer(this);
    timer->setInterval(1000 / difficulty_level);

    connect(timer,SIGNAL(timeout()),this, SLOT(timerTimeout()));

    timer->start();

    last_key = 1;

    progbar->setMinimumSize(QSize(300,10));
    progbar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    setFocus();

}

void ProgressGame::timerTimeout()
{
    setFocus();
    if(progbar->value() < 100) progbar->setValue(progbar->value() > 0 ? progbar->value() - 1 : 0);
}

void ProgressGame::keyPressEvent(QKeyEvent* key_event)
{
    if ( key_event->key() == Qt::Key_A && last_key == 1 ) {
        last_key = 0;
        progbar->setValue(progbar->value() < 100 ? progbar->value() + 1 : 100);
    } else if( key_event->key() == Qt::Key_S && last_key == 0 ) {
        last_key = 1;
        progbar->setValue(progbar->value() < 100 ? progbar->value() + 1 : 100);
    }
}
